package com.itheima.mapper;

import com.itheima.domain.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * ClassName:SysUserMapper
 * Package:com.itheima.mapper
 * Description:
 * Date:2021/11/5 18:21
 * Author:liu.min
 */
public interface SysUserMapper {

    //    private int id;
//    private String username;
//    private String email;
//    private String password;
//    private String phonenum;
//    private List<SysRole> rolelist;
    @Insert("insert into sys_user values(#{id},#{username},#{email},#{password},#{phonenum})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    public void save(SysUser user);

    @Update("update sys_user set username=#{username},password=#{password} where id=#{id}")
    public void update(SysUser user);

    @Delete("delete from sys_user where id=#{id}")
    public void delete(int id);

    @Select("select * from sys_user where id=#{id}")
    public SysUser findById(int id);

    @Select("select * from sys_user")
    public List<SysUser> findAll();


    @Select("select * from sys_user")
    @Results({
            //@Result(property = "id", column = "id"),
            @Result(id = true, column = "id", property = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "email", column = "email"),
            @Result(property = "password", column = "password"),
            @Result(property = "phonenum", column = "phonenum"),
            @Result(
                    property = "rolelist",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "com.itheima.mapper.SysRoleMapper.findAllbymidTbId")
            )
    })
    public List<SysUser> findAllincludeRole();


    @Select("select * from sys_user u where u.username=#{username} and u.phonenum=#{phonenum}")
    SysUser findByUsernameAndPassword(@Param("username") String username,@Param("phonenum") String phonenum);

//    @Select("select * from sys_user u where u.username=#{username} and u.password=#{password}")
//    public User findByUsernameAndPassword(String username, String passWord);
}
